<?php
/*
  Template Name: seccion_cc
 */
?>
<?php
//require( dirname(__FILE__) . '/wp-load.php' ); 
setlocale(LC_ALL, 'es_ES');
?>

<?php
//version 
global $wpdb;
$lblogs = $_REQUEST['blogs'];
$blog_list = explode("/", $lblogs);

if ($blog_list != NULL) {
    $bid = '';
    $sqlGetPosts = ""; //print_r($arrayName);
    foreach ($blog_list as $arrayElement) {
        $bid = $arrayElement;
        if ($bid != 1) {
            $tmp_SQL = "(SELECT post_content, post_title, post_author, post_modified_gmt, post_date, $bid as blog_id,guid  FROM wp_" . $bid . "_posts WHERE post_type = 'post' and post_status= 'publish')";
            if (strlen($sqlGetPosts) > 0) {
                $sqlGetPosts .= " UNION ";
            }
            $sqlGetPosts .= $tmp_SQL;
        }
    }
    $sqlGetPosts .= " ORDER BY post_date DESC limit 3";
    $post_list = $wpdb->get_results($sqlGetPosts, ARRAY_A);
    $total=count($post_list);
    if ($total > 0) {
        echo '<div class="newsItem blogLinks"><h2>Blogs</h2><ul class="shortList">';
        $j = 0;
        foreach ($post_list as $post) {
            $title_post = $post["post_title"];
            $fecha_post = explode(":", $post["post_date"]);
            $varaux = explode("-", $fecha_post[0]);
            $varano = $varaux[0];
            //		echo $varano;
            $varmes = $varaux[1];
            //		echo $varmes;
            $vardia = $varaux[2];

            $vardi = explode(" ", $vardia);


            $id_author = $post["post_author"];
            $author = "";
            $datos=get_userdata($id_author);
            $author=$datos->data->display_name;	

            $bid = $post["blog_id"];

            $blog_details = get_blog_details($bid);
		$tmp_blog_name = $blog_details->blogname;
		$tmp_siteurl = $blog_details->siteurl."/";
            $stilo='';
            if ($j==0)
                $stilo=' class="first"';
            if ($j==($total-1))
                $stilo=' class="last"';
                ?>



            
                	<li<?php echo $stilo;?>>
                    	<a target="_blank" href="<?php echo $post['guid']; ?>">
                             <?php
                if ($id_author == '' || $id_author == 1) {
                    echo '<img src="'.get_template_directory_uri().'/images/avatar_default_blogs_ee.jpg" height="88" width="88" style="float: left;"/>';
                } else {

                    echo userphoto__get_userphoto($id_author, 3, '', '', array('style' => 'width:88px; height:88px; float: left;'), get_template_directory_uri().'/images/avatar_default_blogs_ee.jpg', $tmp_siteurl . "files/");
                }
                ?>
                <div class="texto_blog">
                            <h4><?php echo substr($tmp_blog_name, 0, 28); ?></h4>

                            <h5><? echo strftime("%e %B %Y", strtotime($varmes . "/" . $vardi[0] . "/" . $varano)) ?></h5>
                            <p>
                                <?php echo $title_post; ?>
                           </p>
                            <h6>
                                Autor: <span class="autor"><?php echo $author; ?></span>
                            </h6>
                            </div>
                            <div class="clear"></div>
                        </a>

                    </li>
                <?php
                
            $j++;
        }
        echo '</ul></div>';
    }
}
?>